#include <iostream>
#include <memory>
using namespace std;
// 通过建造者模式实现一个复杂对象的创建
class Computer
{
public:
    void SetBorad(const string &Borad)
    {
        _Borad = Borad;
    }
    void SetDisplay(const string &Display)
    {
        _Display = Display;
    }

    virtual void SetOs() = 0;
    virtual void showList()
    {
        cout << "Computer Information:" << endl;
        cout << "\tComputer Borad:" << _Borad << endl;
        cout << "\tComputer Display:" << _Display << endl;
        cout << "\tComputer OS:" << _os << endl;
    }

protected:
    string _Borad;
    string _Display;
    string _os;
};
class MacComputer : public Computer
{
public:
    void SetOs() override
    {
        _os = "Mac Os";
    }
};

class Builder
{
public:
    virtual void BuildBorad(const string &Borad) = 0;
    virtual void BuildDisplay(const string &Display) = 0;
    virtual void BuildOs() = 0;
    virtual shared_ptr<Computer> build() = 0;
};

class MacBuilder : public Builder
{
public:
    MacBuilder() : computer(new MacComputer())
    {
    }

    void BuildBorad(const string &Borad)
    {
        computer->SetBorad(Borad);
    }

    void BuildDisplay(const string &Display)
    {
        computer->SetDisplay(Display);
    }

    void BuildOs()
    {
        computer->SetOs();
    }
    shared_ptr<Computer> build()
    {
        return computer;
    }

private:
    shared_ptr<Computer> computer;
};
/*指挥者类，提供给调⽤者使⽤，通过指挥者来构造复杂产品*/
class Director
{
public:
    Director(Builder *builder) : _builder(builder) {}
    void construct(const string &Borad, const string &Display)
    {
        _builder->BuildBorad(Borad);
        _builder->BuildDisplay(Display);
        _builder->BuildOs();
    }

private:
    shared_ptr<Builder> _builder;
};
int main()
{
    Builder *builder = new MacBuilder();
    shared_ptr<Director> pd(new Director(builder));
    pd->construct("华硕", "三星显示屏");
    shared_ptr<Computer> computer = builder->build();
    computer->showList();
    return 0;
}